define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    if(Config.website_id == '' || Config.website_id == null){
        Config.website_id = 0;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionwebsitepaytype/index/?website_id=' + Config.website_id,
                    add_url: 'feditionwebsitepaytype/add/?website_id=' + Config.website_id,
                    edit_url: 'feditionwebsitepaytype/edit',
                    del_url: 'feditionwebsitepaytype/del',
                    multi_url: 'feditionwebsitepaytype/multi',
                    import_url: 'feditionwebsitepaytype/import',
                    table: 'fedition_websitepaytype',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'website_id', title: __('Website_id'),visible: false,addClass: "selectpage", extend: "data-source='feditionwebsite/index' data-field='name'"},
                        // {field: 'website_name', title: __('Website_id'), operate: false},
                        {field: 'collectiontype_id', title: __('Collectiontype_id'),visible: false,addClass: "selectpage", extend: "data-source='feditioncollectiontype/index' data-field='name'"},
                        {field: 'collectiontype_name', title: __('Collectiontype_id'), operate: false},
                        {field: 'accountpay_id', title: __('Accountpay_id'),visible: false,addClass: "selectpage", extend: "data-source='feditionaccountpay/index' data-field='name'"},
                        {field: 'accountpay_name', title: __('Accountpay_id'), operate: false},
                        {field: 'accountpay_email', title: __('Accountpay_email'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('店铺收款'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('店铺收款明细'),
                                    title: __('店铺收款明细'),
                                    classname: 'btn btn-sm btn-info btn-addtabs',
                                    icon: 'fa fa-try fa-fw',
                                    url: 'feditionaccountpaystore/index?accountpay_id={accountpay_id}'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-accountpay_id").data("params", function(){
                return {custom: {collection_type: $("#c-collectiontype_id").val()}};
            });
            //动态下拉显示多个字段数据信息
            $("#c-accountpay_id").data("formatItem",function (item) {
                return "邮箱账户:"+item.email;
                // return "收款账户:"+item.name+",邮箱账户:"+item.email;
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-accountpay_id").data("params", function(){
                return {custom: {collection_type: $("#c-collectiontype_id").val()}};
            });
            //动态下拉显示多个字段数据信息
            $("#c-accountpay_id").data("formatItem",function (item) {
                return "邮箱账户:"+item.email;
                // return "收款账户:"+item.name+",邮箱账户:"+item.email;
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});